package com.ezcoding.utils;

import java.util.HashMap;
import java.util.Map;

public class StatusUtil {
    private final static String SUCCESS = "success";
    private final static String FAILED = "failed";
    private final static String STATE = "status";
    private final static String MESSAGE = "message";
    private final static String INVALID_PARA_MESSAGE = "参数无效！";

    public static boolean getStatusValue(Map<String, Object> res) {
        return res.get(STATE).equals(SUCCESS);
    }

    public static Map<String, Object> getSuccessStatusWithMessage(Map<String, Object> res, String message) {

        res.put(STATE, SUCCESS);
        res.put(MESSAGE, message);
        return res;
    }

    public static Map<String, Object> getSuccessStatusWithMessage(String message) {
        Map<String, Object> res = new HashMap<>();

        return getSuccessStatusWithMessage(res, message);
    }

    public static Map<String, Object> getSuccessStatusWithEmptyMessage() {
        return getSuccessStatusWithMessage("");
    }

    private static Map<String, Object> getFailedStatusWithMessage(Map<String, Object> res, String message) {

        res.put(STATE, FAILED);
        res.put(MESSAGE, message);
        return res;
    }

    public static Map<String, Object> getFailedStatusWithMessage(String message) {
        Map<String, Object> res = new HashMap<>();

        return getFailedStatusWithMessage(res, message);
    }

    public static Map<String, Object> getFailedStatusWithInvalidParaMessage() {
        return getFailedStatusWithMessage(INVALID_PARA_MESSAGE);
    }

    public static Map<String, Object> getStatus(Map<String, Object> res, boolean status, String successMessage, String failedMessage) {
        return status ? getSuccessStatusWithMessage(res, successMessage) :
                getSuccessStatusWithMessage(res, failedMessage);
    }

    public static Map<String, Object> getStatus(boolean status, String successMessage, String failedMessage) {
        return status ? getSuccessStatusWithMessage(successMessage) : getFailedStatusWithMessage(failedMessage);
    }
}
